package com.aididi.config;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Auther: zx.xu
 * @Description:    es连接配置类
 */
@Configuration
public class EsConfig {

    @Bean
    public TransportClient client() throws UnknownHostException {
        //配置es地址
        InetSocketTransportAddress transportAddress = new InetSocketTransportAddress(
                InetAddress.getByName("localhost"),9300);
        //es集群名称
        Settings settings = Settings.builder().put("cluster.name","my-elasticsearch").build();
        TransportClient client  = new PreBuiltTransportClient(settings);
        client.addTransportAddress(transportAddress);
        return client;
    }
}
